package com.zhyonk.config.propreties;

import com.baidu.aip.bodyanalysis.AipBodyAnalysis;
import com.baidu.aip.face.AipFace;
import com.baidu.aip.imageprocess.AipImageProcess;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

import java.util.Objects;

@Data
@Component
@ConfigurationProperties(prefix = "baidu")
public class BaiduProperties {

    private static String appId;

    private static String apiKey;

    private static String secretKey;

    private AipFace aipFaceClient;

    private AipBodyAnalysis aipBodyAnalysisClient;

    private AipImageProcess aipImageProcessClient;

    public static String getAppId() {
        return appId;
    }

    public void setAppId(String appId) {
        BaiduProperties.appId = appId;
    }

    public static String getApiKey() {
        return apiKey;
    }

    public void setApiKey(String apiKey) {
        BaiduProperties.apiKey = apiKey;
    }

    public static String getSecretKey() {
        return secretKey;
    }

    public void setSecretKey(String secretKey) {
        BaiduProperties.secretKey = secretKey;
    }

    public AipFace getAipFaceClient() {
        if (Objects.isNull(aipFaceClient)){
            aipFaceClient = new AipFace(appId, apiKey, secretKey);
        }
        return aipFaceClient;
    }

    public AipBodyAnalysis  getAipBodyAnalysisClient() {
        if (Objects.isNull(aipBodyAnalysisClient)){
            aipBodyAnalysisClient = new AipBodyAnalysis(appId, apiKey, secretKey);
        }
        return aipBodyAnalysisClient;
    }

    public AipImageProcess  getAipImageProcessClient() {
        if (Objects.isNull(aipImageProcessClient)){
            aipImageProcessClient = new AipImageProcess(appId, apiKey, secretKey);
        }
        return aipImageProcessClient;
    }

    public void setAipFaceClient(AipFace aipFaceClient) {
        this.aipFaceClient = aipFaceClient;
    }
}
